Produced by Araxis Merge on 2021-07-21 10:21:40 +0000. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | /Applications/Ampps/www/Porto v4.0.0/Theme Files/Magento 2.x/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/Filter | Category.php | 2020-06-26 11:11:14 +0000 |
| 2 | /Applications/Ampps/www/Porto v4.0.1/Theme Files/Magento 2.x/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/Filter | Category.php | 2020-06-26 11:11:14 +0000 |
| Description | Between Files 1 and 2 | |
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 1 | 348 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | Consecutive whitespace is treated as a single space |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
| Active line-pairing rules |
No regular expressions were active.
| 1 | <?php | 1 | <?php | |||
| 2 | /** | 2 | /** | |||
| 3 | * Mageplaza | 3 | * Mageplaza | |||
| 4 | * | 4 | * | |||
| 5 | * NOTICE OF LICENSE | 5 | * NOTICE OF LICENSE | |||
| 6 | * | 6 | * | |||
| 7 | * This source file is subject to the Mageplaza.com license that is | 7 | * This source file is subject to the Mageplaza.com license that is | |||
| 8 | * available through the world-wide-web at this URL: | 8 | * available through the world-wide-web at this URL: | |||
| 9 | * https://www.mageplaza.com/LICENSE.txt | 9 | * https://www.mageplaza.com/LICENSE.txt | |||
| 10 | * | 10 | * | |||
| 11 | * DISCLAIMER | 11 | * DISCLAIMER | |||
| 12 | * | 12 | * | |||
| 13 | * Do not edit or add to this file if you wish to upgrade this extension to newer | 13 | * Do not edit or add to this file if you wish to upgrade this extension to newer | |||
| 14 | * version in the future. | 14 | * version in the future. | |||
| 15 | * | 15 | * | |||
| 16 | * @category Mageplaza | 16 | * @category Mageplaza | |||
| 17 | * @package Mageplaza_LayeredNavigation | 17 | * @package Mageplaza_LayeredNavigation | |||
| 18 | * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | 18 | * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | |||
| 19 | * @license https://www.mageplaza.com/LICENSE.txt | 19 | * @license https://www.mageplaza.com/LICENSE.txt | |||
| 20 | */ | 20 | */ | |||
| 21 | 21 | |||||
| 22 | namespace Mageplaza\LayeredNavigation\Model\Layer\Filter; | 22 | namespace Mageplaza\LayeredNavigation\Model\Layer\Filter; | |||
| 23 | 23 | |||||
| 24 | use Magento\Catalog\Model\Layer as LayerCatalog; | 24 | use Magento\Catalog\Model\Layer as LayerCatalog; | |||
| 25 | use Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory; | 25 | use Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory; | |||
| 26 | use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; | 26 | use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; | |||
| 27 | use Magento\Catalog\Model\Layer\Filter\ItemFactory; | 27 | use Magento\Catalog\Model\Layer\Filter\ItemFactory; | |||
| 28 | use Magento\CatalogSearch\Model\Layer\Filter\Category as AbstractFilter; | 28 | use Magento\CatalogSearch\Model\Layer\Filter\Category as AbstractFilter; | |||
| 29 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection; | 29 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection; | |||
| 30 | use Magento\Framework\App\RequestInterface; | 30 | use Magento\Framework\App\RequestInterface; | |||
| 31 | use Magento\Framework\Escaper; | 31 | use Magento\Framework\Escaper; | |||
| 32 | use Magento\Framework\Exception\LocalizedException; | 32 | use Magento\Framework\Exception\LocalizedException; | |||
| 33 | use Magento\Framework\Exception\StateException; | 33 | use Magento\Framework\Exception\StateException; | |||
| 34 | use Magento\Store\Model\StoreManagerInterface; | 34 | use Magento\Store\Model\StoreManagerInterface; | |||
| 35 | use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper; | 35 | use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper; | |||
| 36 | 36 | |||||
| 37 | /** | 37 | /** | |||
| 38 | * Class Category | 38 | * Class Category | |||
| 39 | * @package Mageplaza\LayeredNavigation\Model\Layer\Filter | 39 | * @package Mageplaza\LayeredNavigation\Model\Layer\Filter | |||
| 40 | */ | 40 | */ | |||
| 41 | class Category extends AbstractFilter | 41 | class Category extends AbstractFilter | |||
| 42 | { | 42 | { | |||
| 43 | /** @var LayerHelper */ | 43 | /** @var LayerHelper */ | |||
| 44 | protected $_moduleHelper; | 44 | protected $_moduleHelper; | |||
| 45 | 45 | |||||
| 46 | /** @var bool Is Filterable Flag */ | 46 | /** @var bool Is Filterable Flag */ | |||
| 47 | protected $_isFilter = false; | 47 | protected $_isFilter = false; | |||
| 48 | 48 | |||||
| 49 | /** @var Escaper */ | 49 | /** @var Escaper */ | |||
| 50 | private $escaper; | 50 | private $escaper; | |||
| 51 | 51 | |||||
| 52 | /** @var LayerCatalog\Filter\DataProvider\Category */ | 52 | /** @var LayerCatalog\Filter\DataProvider\Category */ | |||
| 53 | private $dataProvider; | 53 | private $dataProvider; | |||
| 54 | 54 | |||||
| 55 | /** | 55 | /** | |||
| 56 | * Category constructor. | 56 | * Category constructor. | |||
| 57 | * | 57 | * | |||
| 58 | * @param ItemFactory $filterItemFactory | 58 | * @param ItemFactory $filterItemFactory | |||
| 59 | * @param StoreManagerInterface $storeManager | 59 | * @param StoreManagerInterface $storeManager | |||
| 60 | * @param LayerCatalog $layer | 60 | * @param LayerCatalog $layer | |||
| 61 | * @param DataBuilder $itemDataBuilder | 61 | * @param DataBuilder $itemDataBuilder | |||
| 62 | * @param Escaper $escaper | 62 | * @param Escaper $escaper | |||
| 63 | * @param CategoryFactory $dataProviderFactory | 63 | * @param CategoryFactory $dataProviderFactory | |||
| 64 | * @param LayerHelper $moduleHelper | 64 | * @param LayerHelper $moduleHelper | |||
| 65 | * @param array $data | 65 | * @param array $data | |||
| 66 | * | 66 | * | |||
| 67 | * @throws LocalizedException | 67 | * @throws LocalizedException | |||
| 68 | */ | 68 | */ | |||
| 69 | public function __construct( | 69 | public function __construct( | |||
| 70 | ItemFactory $filterItemFactory, | 70 | ItemFactory $filterItemFactory, | |||
| 71 | StoreManagerInterface $storeManager, | 71 | StoreManagerInterface $storeManager, | |||
| 72 | LayerCatalog $layer, | 72 | LayerCatalog $layer, | |||
| 73 | DataBuilder $itemDataBuilder, | 73 | DataBuilder $itemDataBuilder, | |||
| 74 | Escaper $escaper, | 74 | Escaper $escaper, | |||
| 75 | CategoryFactory $dataProviderFactory, | 75 | CategoryFactory $dataProviderFactory, | |||
| 76 | LayerHelper $moduleHelper, | 76 | LayerHelper $moduleHelper, | |||
| 77 | array $data = [] | 77 | array $data = [] | |||
| 78 | ) { | 78 | ) { | |||
| 79 | parent::__construct( | 79 | parent::__construct( | |||
| 80 | $filterItemFactory, | 80 | $filterItemFactory, | |||
| 81 | $storeManager, | 81 | $storeManager, | |||
| 82 | $layer, | 82 | $layer, | |||
| 83 | $itemDataBuilder, | 83 | $itemDataBuilder, | |||
| 84 | $escaper, | 84 | $escaper, | |||
| 85 | $dataProviderFactory, | 85 | $dataProviderFactory, | |||
| 86 | $data | 86 | $data | |||
| 87 | ); | 87 | ); | |||
| 88 | 88 | |||||
| 89 | $this->escaper = $escaper; | 89 | $this->escaper = $escaper; | |||
| 90 | $this->_moduleHelper = $moduleHelper; | 90 | $this->_moduleHelper = $moduleHelper; | |||
| 91 | $this->dataProvider = $dataProviderFactory->create(['layer' => $this->getLayer()]); | 91 | $this->dataProvider = $dataProviderFactory->create(['layer' => $this->getLayer()]); | |||
| 92 | } | 92 | } | |||
| 93 | 93 | |||||
| 94 | /** | 94 | /** | |||
| 95 | * @inheritdoc | 95 | * @inheritdoc | |||
| 96 | */ | 96 | */ | |||
| 97 | public function apply(RequestInterface $request) | 97 | public function apply(RequestInterface $request) | |||
| 98 | { | 98 | { | |||
| 99 | if (!$this->_moduleHelper->isEnabled()) { | 99 | if (!$this->_moduleHelper->isEnabled()) { | |||
| 100 | return parent::apply($request); | 100 | return parent::apply($request); | |||
| 101 | } | 101 | } | |||
| 102 | 102 | |||||
| 103 | $categoryId = $request->getParam($this->_requestVar); | 103 | $categoryId = $request->getParam($this->_requestVar); | |||
| 104 | if (empty($categoryId)) { | 104 | if (empty($categoryId)) { | |||
| 105 | return $this; | 105 | return $this; | |||
| 106 | } | 106 | } | |||
| 107 | 107 | |||||
| 108 | $categoryIds = []; | 108 | $categoryIds = []; | |||
| 109 | foreach (explode(',', $categoryId) as $id) { | 109 | foreach (explode(',', $categoryId) as $id) { | |||
| 110 | $this->dataProvider->setCategoryId($id); | 110 | $this->dataProvider->setCategoryId($id); | |||
| 111 | if ($this->dataProvider->isValid()) { | 111 | if ($this->dataProvider->isValid()) { | |||
| 112 | $category = $this->dataProvider->getCategory(); | 112 | $category = $this->dataProvider->getCategory(); | |||
| 113 | if ($request->getParam('id') !== $id) { | 113 | if ($request->getParam('id') !== $id) { | |||
| 114 | $categoryIds[] = $id; | 114 | $categoryIds[] = $id; | |||
| 115 | $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id)); | 115 | $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id)); | |||
| 116 | } | 116 | } | |||
| 117 | } | 117 | } | |||
| 118 | } | 118 | } | |||
| 119 | 119 | |||||
| 120 | if (!empty($categoryIds)) { | 120 | if (!empty($categoryIds)) { | |||
| 121 | $this->_isFilter = true; | 121 | $this->_isFilter = true; | |||
| 122 | $this->getLayer()->getProductCollection()->addLayerCategoryFilter($categoryIds); | 122 | $this->getLayer()->getProductCollection()->addLayerCategoryFilter($categoryIds); | |||
| 123 | } | 123 | } | |||
| 124 | 124 | |||||
| 125 | if ($parentCategoryId = $request->getParam('id')) { | 125 | if ($parentCategoryId = $request->getParam('id')) { | |||
| 126 | $this->dataProvider->setCategoryId($parentCategoryId); | 126 | $this->dataProvider->setCategoryId($parentCategoryId); | |||
| 127 | } | 127 | } | |||
| 128 | 128 | |||||
| 129 | return $this; | 129 | return $this; | |||
| 130 | } | 130 | } | |||
| 131 | 131 | |||||
| 132 | /** | 132 | /** | |||
| 133 | * @return array | 133 | * @return array | |||
| 134 | * @throws StateException | 134 | * @throws StateException | |||
| 135 | */ | 135 | */ | |||
| 136 | protected function _getItemsData() | 136 | protected function _getItemsData() | |||
| 137 | { | 137 | { | |||
| 138 | if (!$this->_moduleHelper->isEnabled()) { | 138 | if (!$this->_moduleHelper->isEnabled()) { | |||
| 139 | return parent::_getItemsData(); | 139 | return parent::_getItemsData(); | |||
| 140 | } | 140 | } | |||
| 141 | 141 | |||||
| 142 | /** @var Collection $productCollection */ | 142 | /** @var Collection $productCollection */ | |||
| 143 | $productCollection = $this->getLayer()->getProductCollection(); | 143 | $productCollection = $this->getLayer()->getProductCollection(); | |||
| 144 | 144 | |||||
| 145 | if ($this->_isFilter) { | 145 | if ($this->_isFilter) { | |||
| 146 | $productCollection = $productCollection->getCollectionClone() | 146 | $productCollection = $productCollection->getCollectionClone() | |||
| 147 | ->removeAttributeSearch('category_ids'); | 147 | ->removeAttributeSearch('category_ids'); | |||
| 148 | } | 148 | } | |||
| 149 | 149 | |||||
| 150 | $optionsFacetedData = $productCollection->getFacetedData('category'); | 150 | $optionsFacetedData = $productCollection->getFacetedData('category'); | |||
| 151 | $category = $this->dataProvider->getCategory(); | 151 | $category = $this->dataProvider->getCategory(); | |||
| 152 | $categories = $category->getChildrenCategories(); | 152 | $categories = $category->getChildrenCategories(); | |||
| 153 | 153 | |||||
| 154 | $collectionSize = $productCollection->getSize(); | 154 | $collectionSize = $productCollection->getSize(); | |||
| 155 | 155 | |||||
| 156 | if ($category->getIsActive()) { | 156 | if ($category->getIsActive()) { | |||
| 157 | foreach ($categories as $childCategory) { | 157 | foreach ($categories as $childCategory) { | |||
| 158 | $count = isset($optionsFacetedData[$childCategory->getId()]) | 158 | $count = isset($optionsFacetedData[$childCategory->getId()]) | |||
| 159 | ? $optionsFacetedData[$childCategory->getId()]['count'] : 0; | 159 | ? $optionsFacetedData[$childCategory->getId()]['count'] : 0; | |||
| 160 | if ($childCategory->getIsActive() | 160 | if ($childCategory->getIsActive() | |||
| 161 | && $this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $collectionSize) | 161 | && $this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $collectionSize) | |||
| 162 | ) { | 162 | ) { | |||
| 163 | $this->itemDataBuilder->addItemData( | 163 | $this->itemDataBuilder->addItemData( | |||
| 164 | $this->escaper->escapeHtml($childCategory->getName()), | 164 | $this->escaper->escapeHtml($childCategory->getName()), | |||
| 165 | $childCategory->getId(), | 165 | $childCategory->getId(), | |||
| 166 | $count | 166 | $count | |||
| 167 | ); | 167 | ); | |||
| 168 | } | 168 | } | |||
| 169 | } | 169 | } | |||
| 170 | } | 170 | } | |||
| 171 | 171 | |||||
| 172 | return $this->itemDataBuilder->build(); | 172 | return $this->itemDataBuilder->build(); | |||
| 173 | } | 173 | } | |||
| 174 | } | 174 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993–2019 Araxis Ltd (www.araxis.com). All rights reserved.